{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>发布消息</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="n_title" lay-verify="required" placeholder="标题" class="layui-input ">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block">
                                <textarea lay-verify="required" name="n_content" class="layui-input " style="height:80px"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">推送范围：</label>
                            <div class="layui-input-block">
                                <select name="n_range" lay-filter="role1">
                                    <option value="1" selected>全部</option>
                                    <option value="2" >个别</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="user_id">
                            <label class="layui-form-label">选择用户：</label>
                            <div class="layui-input-block">
                                <select name="n_user_id"  xm-select="select2" xm-select-search="" xm-select-search-type="dl">
                                <!--<select name="n_user_id"  lay-search>-->
                                    <option value="" >请选择</option>
                                    {foreach name="user" item="v"}
                                    <option value="{$v.user_id}" >{$v.user_id}：{$v.user_username}({$v.user_phone})</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">发布
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form','upload','layedit','laydate'], function() {
        var form = layui.form;

        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('noticeAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Notice/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        // 推送人群
        form.on('select(role1)', function(data){
            if(data.value == 1){
                $("#user_id").hide();
            }else{
                $("#user_id").show();
            }
        });
    });
</script>

</body>
</html>
